package com.bing.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authc.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.bing.entity.LoanProducts.LoanProductinfo;
import com.bing.mapper.LoanProdductsinfoMapper;

@Service
public class LoanProdductsinfoService   {

    private Integer PAGE_SIZE = 15;

    private Integer APP_PAGE_SIZE = 10;

    @Autowired
    private LoanProdductsinfoMapper loanProdductsinfoMapper;


    public int insert(LoanProductinfo loanProdductsinfo){
        return loanProdductsinfoMapper.insert(loanProdductsinfo);
    }


    public int insertSelective(LoanProductinfo loanProdductsinfo){
        return loanProdductsinfoMapper.insertSelective(loanProdductsinfo);
    }


    public int insertList(List<LoanProductinfo> loanProdductsinfos){
        return loanProdductsinfoMapper.insertList(loanProdductsinfos);
    }


    public int updateByPrimaryKeySelective(LoanProductinfo loanProdductsinfo){
        return loanProdductsinfoMapper.updateByPrimaryKeySelective(loanProdductsinfo);
    }


    public PageInfo<LoanProductinfo> getProuctList(Integer pageNum) {
        PageHelper.startPage(pageNum, PAGE_SIZE);
        List<LoanProductinfo> loanProductinfos = loanProdductsinfoMapper.getProuctList();
        return new PageInfo<LoanProductinfo>(loanProductinfos);
    }

    public Map<String , String> getIdNameMap() {
        List<LoanProductinfo> loanProductinfos = loanProdductsinfoMapper.getProuctList();
        return loanProductinfos.stream().collect(Collectors.toMap(LoanProductinfo::getProductId, LoanProductinfo::getProductName));
    }

    public LoanProductinfo getProductDetail(String productId) {
         return loanProdductsinfoMapper.getProductDetail(productId);
    }

    /**
     * app列表
     * @param productType
     * @param firstPage
     * @return
     */
    public PageInfo<LoanProductinfo> getProuctListBywhere(String productType, String firstPage,Integer pageNum) {
        PageHelper.startPage(pageNum, APP_PAGE_SIZE);
        List<LoanProductinfo> loanProductinfos =  loanProdductsinfoMapper.getProuctListBywhere(productType,firstPage);
        return new PageInfo<>(loanProductinfos);
    }

    public String getProdId() {
        return loanProdductsinfoMapper.getProdId();
    }
}
